function getUrlParms(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return r[2]; return null;
}

let nameOne = getUrlParms("productid");
let nameTwo = getUrlParms("categoryid");
let nameThree = getUrlParms("productName");

let productid = decodeURI(nameOne)
let categoryId = decodeURI(nameTwo)
let productName = decodeURI(nameThree)
console.log(productName);
//标题渲染
$.ajax({
    url: `http://chst.vip:1234/api/getcategorybyid?categoryid=${categoryId}`
})
    .then(res => {
        console.log(res);
        let name = res.result[0]['category']
        let as = `
        <a href="index.html">首页&gt</a>
        <a href="bijia.html?title=${name}&categoryid=${categoryId}">${name}&gt</a>
        <a href="productlist.html">${productName}</a>
        <a href="">筛选</a>`
        console.log(as);
        $("#subNav")[0].innerHTML = as
    })


$.ajax({
    url: `http://chst.vip:1234/api/getproduct?productid=${productid}`

})
    .then(res => {
        $("#subNav>a:eq(2)")[0].innerText = `${res.result[0]['productName']}&gt`
        return res
    })

    .then(res => {
        let span1 = ` <div class="spanPic">${res.result[0].productImg}</div>
            <div class="imgtitle">${res.result[0].productName}</div>
            <div class="jiage">
                <div>
                    <span>当前最低</span>
                    <span>6000</span>
                </div>
                <div>
                    <span>优选评论</span>
                    <span>8662条</span>
                </div>   
            </div>`
        $("#main>.span1")[0].innerHTML = span1

        let span2 = `<div class="makeprice">${res.result[0].bjShop}</div>`
        $("#main>.span2")[0].innerHTML = span2
        return res
    })


$.ajax({
    url: `http://chst.vip:1234/api/getproductcom?productid=${productid}`
})
    .then(res => {
        let div = ''
        res.result.forEach(item => {
            div += `
                <div class="info">
                    <div>
                        <div>${item.comName}</div>
                        <div>${item.comTime}</div>
                    </div>
                    <div>${item.comContent}</div>
                    <div>${item.comFrom}</div>
                </div>
            `
        })
        $('.span3')[0].innerHTML = div
    })

$("#footer>.dengruSpan>.backTop").click(function () {
    $("html").animate({ scrollTop: 0 }, 1000)
})

